home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / os2 / mbase101.zip / macplug.Zip / printrec.nrx < prev    next >
Text File  |  1997-04-15  |  5KB  |  200 lines

  1. /* 
  2.    PrintRec, a NetRexx app to create text documents 
  3.    from selected records for printing
  4. */
  5.  
  6. class printrec extends Frame
  7.  
  8. properties public
  9.  
  10. rx = RXFile()
  11. rxPrint = RXFile()
  12. rHowManyFld = Rexx
  13. rHowManyRec = Rexx
  14. rFieldName = Rexx[]
  15. rFieldValue = Rexx[,]
  16. iCount = int
  17. iCount2 = int
  18. iMaxLength = 0
  19. bPrintHeader = boolean 1
  20. bPrintFieldNames = boolean 1
  21. bActuallyPrint = boolean 1
  22. rPrintCommand = Rexx "cmd.exe /c copy printme.txt lpt1:"
  23. rHeader1 = Rexx "MaxBase 1.0, Copyright 1997 Max Marsiglietti -- record dump"
  24. rHeader2 = Rexx "------- ---- --------- ---- --- ------------ -- ------ ----"
  25. rtime = Runtime
  26. pr2 = Process
  27.  
  28. pCenter = Panel -- Here we'll lay all the other textfields/areas, labels.
  29. cbActuallyPrint = CheckBox("Execute command")
  30. cbPrintHeader = CheckBox("Print Header")
  31. cbPrintFieldNames = CheckBox("Also print Field Names")
  32. laHeader1 = Label("Header Line 1:")
  33. laHeader2 = Label("Header Line 2:")
  34. tfHeader1 = TextField(rHeader1)
  35. tfHeader2 = TextField(rHeader2)
  36. laPrintCommand = Label("Print Command:")
  37. tfPrintCommand = TextField(rPrintCommand)
  38. bPrintIt = Button("Create printme.txt file")
  39. bExit = Button("Exit")
  40.  
  41.  
  42.  
  43. method main(s=String[]) static
  44.  s=s
  45.  printrec()
  46.  
  47.  
  48. method printrec
  49.  
  50. super("Record Printing: 1 record")
  51. super.setResizable(1)
  52.  
  53. rHowManyFld = rx.linein() /* How many fields? */
  54. rFieldName = Rexx[rHowManyFld + 1]
  55.  
  56. loop iCount = 1 to rHowManyFld
  57.  rFieldName[iCount] = rx.linein() /* Get field names */
  58.  if rFieldName[iCount].length > iMaxLength then
  59.   iMaxLength = rFieldName[iCount].length
  60. end
  61.  
  62. rHowManyRec = rx.linein() /* How many records? */
  63. rFieldValue = Rexx[rHowManyFld + 1, rHowManyRec + 1]
  64.  
  65. loop iCount = 1 to rHowManyRec /* Records */
  66.  loop iCount2 = 1 to rHowManyFld
  67.   rFieldValue[iCount2, iCount] = rx.linein()
  68.  end
  69. end
  70.  
  71. /* 
  72.  
  73.    Now we have:
  74.       in rFieldName[1..rHowManyFld] all the field names.
  75.       in rFieldValue[1..rHowManyFld, 1..rHowManyRec] all the records that the user
  76.       has selected before calling the plugin, field by field and record by record.
  77.  
  78.  
  79. */
  80.  
  81.  loop iCount = 1 to rHowManyFld
  82.   rFieldName[iCount] = rFieldName[iCount].left(iMaxLength)
  83.  end
  84.  
  85.  setupFrame
  86.  
  87.  
  88. method setupFrame
  89.  pOne = Panel()
  90.  pTwo = Panel()
  91.  pThree = Panel()
  92.  pFour = Panel()
  93.  pFive = Panel()
  94.  
  95.  tfPrintCommand.setBackGround(Color(255, 255, 204))
  96.  tfHeader1.setBackGround(Color(255, 255, 204))
  97.  tfHeader2.setBackGround(Color(255, 255, 204))
  98.  cbActuallyPrint.setState(bActuallyPrint)
  99.  cbPrintHeader.setState(bPrintHeader)
  100.  cbPrintFieldNames.setState(bPrintFieldNames)
  101.  pCenter = Panel()
  102.  pCenter.setLayout(GridLayout(4, 1))
  103.  pCenter.removeAll
  104.  
  105.  pOne.setLayout(FlowLayout(FlowLayout.LEFT))
  106.  pOne.add(laHeader1)
  107.  pOne.add(tfHeader1)
  108.  pCenter.add(pOne)
  109.  
  110.  pTwo.setLayout(FlowLayout(FlowLayout.LEFT))
  111.  pTwo.add(laHeader2)
  112.  pTwo.add(tfHeader2)
  113.  pCenter.add(pTwo)
  114.  
  115.  pThree.setLayout(FlowLayout(FlowLayout.LEFT))
  116.  pThree.add(laPrintCommand)
  117.  pThree.add(tfPrintCommand)
  118.  pCenter.add(pThree)
  119.  
  120.  pFour.setLayout(FlowLayout(FlowLayout.LEFT))
  121.  pFour.add(cbActuallyPrint)
  122.  pFour.add(cbPrintHeader)
  123.  pFour.add(cbPrintFieldNames)
  124.  pCenter.add(pFour)
  125.  
  126.  pFive.setLayout(FlowLayout(FlowLayout.CENTER))
  127.  pFive.add(bPrintIt)
  128.  pFive.add(bExit)
  129.  
  130.  this.add("Center", pCenter)
  131.  this.add("South", pFive)
  132.  this.reshape(Toolkit.getDefaultToolkit.getScreenSize.width % 2 - 320, Toolkit.getDefaultToolkit.getScreenSize.height %2 - 100, 640, 200)
  133.  if rHowManyRec > 1 then
  134.   this.setTitle("Record printing: "rHowManyRec" records")
  135.  this.show()
  136.  
  137.  
  138. method handleEvent(e=Event) returns boolean
  139.   if e.target = bPrintIt then PrintIt
  140.   if e.target = bExit then exit
  141.   if e.id=Event.WINDOW_DESTROY then 
  142.    exit
  143.   return super.handleEvent(e)
  144.  
  145.  
  146.  
  147.  
  148. method Printit
  149.  
  150.  bActuallyPrint = cbActuallyPrint.getState()
  151.  bPrintHeader   = cbPrintHeader.getState()
  152.  bPrintFieldNames   = cbPrintFieldNames.getState()
  153.  rHeader1 =  tfHeader1.getText()
  154.  rHeader2 =  tfHeader2.getText()
  155.  rPrintCommand =  tfPrintCommand.getText()
  156.  
  157.  -- If the file already exists, delete it
  158.  if rxPrint.stream("printme.txt", "c", "query exists") \= "" then
  159.   rxPrint.delete("printme.txt")
  160.  
  161.  -- Create the file
  162.  rxPrint.stream("printme.txt", "c", "open write")
  163.  
  164.  -- create the header
  165.  if bPrintHeader = 1 then
  166.  do
  167.   rxPrint.lineout(rHeader1)
  168.   rxPrint.lineout(rHeader2)
  169.   rxPrint.lineout(" ")
  170.  end
  171.  
  172.  -- now the records (in form view)
  173.  loop iCount = 1 to rHowManyRec
  174.   loop iCount2 = 1 to rHowManyFld
  175.    if bPrintFieldNames = 1 then
  176.     rxPrint.lineout(rFieldName[iCount2] || " : " || rFieldValue[iCount2, iCount].strip())
  177.    else
  178.     rxPrint.lineout(rFieldValue[iCount2, iCount].strip())
  179.   end
  180.   rxPrint.lineout("--")
  181.   rxPrint.lineout(" ")
  182.  end
  183.  -- Close the stream
  184.  rxPrint.stream("printme.txt", "c", "close")
  185.  
  186.  if bActuallyPrint = 1 then
  187.  do
  188.   /* fire up the printing command */
  189.   rtime = Runtime.getRuntime()
  190.   do
  191.    pr2 = rtime.exec(rPrintCommand)
  192.    pr2.waitfor()
  193.   catch IOException
  194.   catch InterruptedException
  195.   catch NullPointerException
  196.    exit
  197.   end
  198.  end
  199.  
  200.